/*
 * Copyright (C) 2017 Pingan, Inc. All Rights Reserved.
 */
package com.pingan.haofang.searchcloud.api.schema;

import java.util.ArrayList;
import java.util.List;

/**
 * @author huhailiang937
 * @date 2017年5月3日下午8:53:54
 * @since 1.0.0
 */
public class IndexSchema {

    /**
     * Schema名称
     */
    protected String indexName;

    /**
     * Index的主键字段
     */
    protected SchemaField uniqueKey;

    /**
     * Index全部字段
     */
    protected List<SchemaField> fields = new ArrayList<SchemaField>(20);

    /**
     * Index全部copy字段
     */
    protected List<SchemaCopyField> copyFields = new ArrayList<SchemaCopyField>(5);

    public IndexSchema addField(SchemaField field) {
        fields = (null == fields) ? new ArrayList<SchemaField>(20) : fields;

        if (field.isUniqueKey()) {
            uniqueKey = field;
        }
        fields.remove(field);
        fields.add(field);
        return this;
    }

    public IndexSchema addCopyField(SchemaCopyField field) {
        copyFields = (null == copyFields) ? new ArrayList<SchemaCopyField>(5) : copyFields;
        copyFields.add(field);
        return this;
    }


    public SchemaField getUniqueKey() {
        return uniqueKey;
    }

    public void setUniqueKey(SchemaField uniqueKey) {
        this.uniqueKey = uniqueKey;
    }

    public List<SchemaField> getFields() {
        return fields;
    }

    public void setFields(List<SchemaField> fields) {
        this.fields = fields;
    }

    public List<SchemaCopyField> getCopyFields() {
        return copyFields;
    }

    public void setCopyFields(List<SchemaCopyField> copyFields) {
        this.copyFields = copyFields;
    }

    public String getIndexName() {
        return indexName;
    }

    public void setIndexName(String indexName) {
        this.indexName = indexName;
    }

}
